package advanced.io;

import java.io.*;

public class L_BufferedInputStream {
    public static void main(String[] args) {

    }

    /**
     * 缓冲输入流
     *
     * @param bis
     */
    public static void bufferedInput(BufferedInputStream bis) {
        File src = new File("abc.txt");
        try (bis) {
            //操作逻辑
            byte[] flush = new byte[1024];
            int len = -1; //接收长度
            while ((len = bis.read(flush)) != -1) {
                String str = new String(flush, 0, len);
                System.out.println(str);
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void bufferedOutput(BufferedOutputStream bos, String msg) {
        try (bos) {
            //操作逻辑
            bos.write(msg.getBytes());
            bos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
